package hlhj.fhp.supreme.activitys

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import hlhj.fhp.supreme.BaseAty
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.javabean.BaseBean
import hlhj.fhp.supreme.javabean.UserInfoBean
import hlhj.fhp.supreme.network.Urls
import hlhj.fhp.supreme.utils.JsonCallBack
import hlhj.fhp.supreme.utils.MyUtils
import hlhj.fhp.supreme.utils.SPHelper
import kotlinx.android.synthetic.main.activity_change_nick_aty.*

class ChangeNickAty : BaseAty(){
    private lateinit var userInfo:UserInfoBean.DataBean
    override fun getContentId(): Int {
        return R.layout.activity_change_nick_aty
    }

    override fun initView() {
        userInfo=SPHelper.getUser(this) as UserInfoBean.DataBean
        etNick.setHint(userInfo.user_nickname)


    }

    override fun initListener() {
        btCommit.setOnClickListener {
            if (etNick.text.toString().length==0){
                MyUtils.toast("请修改您的昵称")
            }else{
                OkGo.post<BaseBean>(Urls.BaseUrl+Urls.CHANGEINFO)
                        .params("user_nickname",etNick.text.toString())
                        .execute(object :JsonCallBack<BaseBean>(this){
                            override fun onSuccess(response: Response<BaseBean>?) {
                                val bean = response?.body()
                                if (bean?.code==1){
                                    MyUtils.toast("修改成功")
                                    finish()
                                }
                            }
                        })

            }
        }
        btExit.setOnClickListener { finish() }
    }
}

